<?php 

//用护控制中心
class UserAction extends GlobalAction{
	function _initialize(){			 
		 parent::_initialize();	
         LL('user');
		 LC('@.Help.transaction');
		 $GLOBALS['_LANG']=L();
		 /*
		$this->cookie_status = isset($_COOKIE['sid']) ? 1 : 0;
		$sid = $this->cookie_status ? getgpc('sid', 'C') : rawurlencode(getgpc('sid', 'R'));
		
		$this->view->sid = $sid;
	 
		$this->assign('sid', $this->view->sid);	
	 */
	}
	 
	public function index(){	
		   //跳转到用户中心;
		   U('User/usercenter','',true);
          // $this->usercenter();
       
	}
	//用户注册协议;
	public function Agreement(){	
		 $this->display();
       
	}
	/* 未登录处理 */
    public function un_login(){	
	 
		if (empty($_SESSION['user_id'])){
			U('User/login','',true);		 
		}else{
		
		}	
	}

	//用户登录
	public function login(){
		if (!empty($_SESSION['user_id'])){
			 	U('User/usercenter','',true); 		
		}	
		$back_act=unescape($this->getby('back'));
		$back_act=str_replace('_','/',$back_act);
		$back_act=U($back_act);
		if (empty($back_act) && isset($GLOBALS['_SERVER']['HTTP_REFERER'])){
			$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'User') ? 'Default' : $GLOBALS['_SERVER']['HTTP_REFERER'];
		}		 
	//	echo $back_act;
		$this->assign('back_act',$back_act);
		$this->display();
	}

    //处理用户登录
	public function act_login(){	
		$_LANG=L();	
		$username = isset($_POST['username']) ? trim($_POST['username']) : '';
		$password = isset($_POST['password']) ? trim($_POST['password']) : '';
		$back_act = isset($_POST['back_act']) ? trim($_POST['back_act']) : U('Default/index');
		if (G('user')->login($username, $password)){
			update_user_info();
			recalculate_price();
			$this->view->sid = $this->sid_encode($this->user['username']);			
			$this->setcookie('MDL[mysid]', $this->view->sid, 86400);
			 
			$ucdata = isset(G('user')->ucdata)? G('user')->ucdata : '';
			//U('Default/index','',true);
			echo $back_act;
			//exit;
			redirect($back_act);
			//$this->show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,U('User/index')), 'info');
		}else{
			$_SESSION['login_fail'] ++ ;
			$this->show_message($_LANG['login_failure'], $_LANG['relogin_lnk'], U('User/index'), 'error');
		}

	}
	//用户注册
	public function reg(){	   
	    if (!$GLOBALS['_CFG']['shop_reg_closed']){
			$this->show_message($GLOBALS['_LANG']['shop_register_closed']);
		}
	    if (!isset($back_act) && isset($GLOBALS['_SERVER']['HTTP_REFERER'])){
			 $back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'user.php') ? './index.php' : $GLOBALS['_SERVER']['HTTP_REFERER'];
        }
 	    $username=md5(gmtime()+real_ip());
		$this->assign('username',$username);
		$this->assign('back_act',$back_act);		
		$this->assign('lang',      L());
		$this->display();
	}	
	//处理注册
    public function act_reg(){
		$code=isset($_POST['code'])?strtoupper(trim($_POST['code'])):'';
		if(!isset($_SESSION['scode'])){
			$this->show_message('- 验证码不正确');
		}
		LC("M.lib.seccode",true);
		$code_o = new seccode();
		$code_o->seccodeconvert($_SESSION['scode']);
		if($_SESSION['scode']!=$code){
			$this->show_message('- 验证码不正确');
		}

	    LC('@.Help.passport');
	    $username = isset($_POST['username']) ? trim($_POST['username']) : '';
        $password = isset($_POST['password']) ? trim($_POST['password']) : '';
        $email    = isset($_POST['email']) ? trim($_POST['email']) : '';
		$username=$email;
        $other = isset($_POST['other']) ? $_POST['other'] : array();
        $back_act = isset($_POST['back_act']) ? trim($_POST['back_act']) : '';
		$_LANG=L();		
        if(empty($_POST['agreement'])){
            $this->show_message($_LANG['passport_js']['agreement']);
        }
        /*
        if (strlen($username) < 3){
            $this->show_message($_LANG['passport_js']['username_shorter']);
        }*/

        if (strlen($password) < 6){
            $this->show_message($_LANG['passport_js']['password_shorter']);
        }
     
        if (register($username, $password, $email, $other) !== false){
            $ucdata = empty(G('user')->ucdata)? "" : G('user')->ucdata;			 
            U('Default/index','',true);
			//$this->show_message(sprintf($_LANG['register_success'], $email . $ucdata), array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act, U('User/usercenter')), 'info');
        }else{
            G('err')->show($_LANG['sign_up'], U('User/reg'));
        }	
	}
	//退出登录
	public function logout(){
	     if (!isset($back_act) && isset($GLOBALS['_SERVER']['HTTP_REFERER'])){
			$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'user.php') ? './index.php' : $GLOBALS['_SERVER']['HTTP_REFERER'];
		}
		G('user')->logout();
		//$this->setcookie('sid', '');
		$ucdata = empty(G('user')->ucdata)? "" : G('user')->ucdata;
	    U('Default/index','',true);
		//$this->show_message(L('logout') . $ucdata, array(L('back_up_page'), L('back_home_lnk') ), array($back_act, U('Default/index')), 'info');
	
	}
	//用户中心;
	public function usercenter(){
	    $this->un_login();
		$_LANG=L();
        $history=$this->get_history();	
		$user_id = $_SESSION['user_id'];
		if ($rank = get_rank_info()){
			$this->assign('rank_name', sprintf($_LANG['your_level'], $rank['rank_name']));
			if (!empty($rank['next_rank_name']))
			{
				$this->assign('next_rank_name', sprintf($_LANG['next_level'], $rank['next_rank'] ,$rank['next_rank_name']));
			}
		 }
		 $orders = get_user_orders($user_id, 10);
		$orders_len = count($orders);
		$this->assign('orders_len',        $orders_len);
		 $this->assign('orders',        $orders);
		$this->assign('info',        get_user_default($user_id));
		//dump( get_user_default($user_id)   );
		$this->assign('user_notice', $_CFG['user_notice']);
	//	$this->assign('prompt',      get_user_prompt($user_id));

		 $this->assign('user', get_profile($user_id));
		 $record_count = G('db')->getOne("SELECT COUNT(*) FROM " .gettable('order_info'). " WHERE user_id = '$user_id'");
		 $this->assign('order_num', $record_count);
		//  dump(get_profile($user_id));
		$this->assign('history',$history);
	    $this->display();
	
	}
		//用户登录
	public function forgetpwd(){
		 	
		$back_act=unescape($this->getby('back'));
		$back_act=str_replace('_','/',$back_act);
		$back_act=U($back_act);
		if (empty($back_act) && isset($GLOBALS['_SERVER']['HTTP_REFERER'])){
			$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'User') ? 'Default' : $GLOBALS['_SERVER']['HTTP_REFERER'];
		}	
		
	 
		$this->assign('back_act',$back_act);
		$this->display();





	}
	//用户登录
	public function act_forgetpwd(){

		LC('@.Help.passport');
	   $_LANG=L();
		/* 初始化会员用户名和邮件地址 */
		$user_name = !empty($_POST['user_name']) ? trim($_POST['user_name']) : '';
		$email     = !empty($_POST['email'])     ? trim($_POST['email'])     : '';
		
		//用户名和邮件地址是否匹配
		$user_info = G('user')->get_user_info($user_name);
 
		if ($user_info && $user_info['email'] == $email)
		{
			//生成code
			 //$code = md5($user_info[0] . $user_info[1]);

			$code = md5($user_info['user_id'] . $_CFG['hash_code'] . $user_info['reg_time']);
			//发送邮件的函数
			if (send_pwd_email($user_info['user_id'], $user_name, $email, $code))
			{
				$this->show_message($_LANG['send_success'] . $email, $_LANG['back_home_lnk'], './', 'info');
			}
			else
			{
				//发送邮件出错
				$this->show_message($_LANG['fail_send_password'], $_LANG['back_page_up'], './', 'info');
			}
		}
		else
		{
			//用户名与邮件地址不匹配
			$this->show_message($_LANG['username_no_email'], $_LANG['back_page_up'], '', 'info');
		}	 
	}
	public function getpassword(){
			LC('@.Help.passport');
	        $_LANG=L();
            $code=$this->getby('code');
			$uid=$this->getby('uid');
			
			if (isset($code) && isset($uid) ){
				$code = trim($code);
				$uid  = intval($uid);
				 
				/* 判断链接的合法性 */
				$user_info = G('user')->get_profile_by_id($uid);
				if (empty($user_info) || ($user_info && md5($user_info['user_id'] . $GLOBALS['_CFG']['hash_code'] . $user_info['reg_time']) != $code))
				{
					$this->show_message($_LANG['parm_error'], $_LANG['back_home_lnk'], './', 'info');
				}
 
				$this->assign('uid',    $uid);
				$this->assign('code',   $code);
				$this->assign('action', 'reset_password');
				$this->display();

			}else{
				//显示用户名和email表单
				G('V')->display();
			}	
	}
	public function reeditpwd(){
		LC('@.Help.passport');
	    $_LANG=L();
		$old_password = isset($_POST['old_password']) ? trim($_POST['old_password']) : '';
		$new_password = isset($_POST['new_password']) ? trim($_POST['new_password']) : '';
		$user_id      = isset($_POST['uid'])  ? intval($_POST['uid']) : $user_id;
		$code         = isset($_POST['code']) ? trim($_POST['code'])  : '';

		if (strlen($new_password) < 6)		{
			$this->show_message($_LANG['passport_js']['password_shorter']);
		}

		$user_info = G('user')->get_profile_by_id($user_id); //论坛记录

		if (($user_info && (!empty($code) && md5($user_info['user_id'] . $_CFG['hash_code'] . $user_info['reg_time']) == $code)) || ($_SESSION['user_id']>0 && $_SESSION['user_id'] == $user_id && G('user')->check_user($_SESSION['user_name'], $old_password)))
		{
			if (G('user')->edit_user(array('username'=> (empty($code) ? $_SESSION['user_name'] : $user_info['user_name']), 'old_password'=>$old_password, 'password'=>$new_password), empty($code) ? 0 : 1))
			{
				G('user')->logout();
				$this->show_message($_LANG['edit_password_success'], $_LANG['relogin_lnk'], U('User/login'), 'info');
			}
			else
			{
				$this->show_message($_LANG['edit_password_failure'], $_LANG['back_page_up'], '', 'info');
			}
		}
		else
		{
			$this->show_message($_LANG['edit_password_failure'], $_LANG['back_page_up'], '', 'info');
		}
	
	}

	//用户信息编辑
	public function useredit(){
		$this->un_login();
	    $user_id = $_SESSION['user_id'];
		$this->assign('user', get_profile($user_id));		
		$this->display();
	}
	//修改密码
	public function modpwd(){
		$this->un_login();
		$this->display();
	}
	//重设新密码；
	public function act_edit_password(){
	    $_LANG=L();
	    $user=G('user');
		$old_password = isset($_POST['old_password']) ? trim($_POST['old_password']) : '';
		$new_password = isset($_POST['new_password']) ? trim($_POST['new_password']) : '';
		$user_id      = isset($_POST['uid'])  ? intval($_POST['uid']) : $user_id;
		$code         = isset($_POST['code']) ? trim($_POST['code'])  : '';

		if (strlen($new_password) < 6)
		{
			$this->show_message($_LANG['passport_js']['password_shorter']);
		}
 		$user_id = $_SESSION['user_id'];
		$user_info = $user->get_profile_by_id($user_id); //论坛记录
  		if (($user_info && (!empty($code) && md5($user_info['user_id'] . $_CFG['hash_code'] . $user_info['reg_time']) == $code)) || ($_SESSION['user_id']>0 && $_SESSION['user_id'] == $user_id && $user->check_user($_SESSION['user_name'], $old_password)))
		{
			if ($user->edit_user(array('username'=> (empty($code) ? $_SESSION['user_name'] : $user_info['user_name']), 'old_password'=>$old_password, 'password'=>$new_password), empty($code) ? 0 : 1))
			{
				$user->logout();
				$this->show_message($_LANG['edit_password_success'], $_LANG['relogin_lnk'], U('User/login'), 'info');
			}
			else
			{
				$this->show_message($_LANG['edit_password_failure'], $_LANG['back_page_up'], '', 'info');
			}
		}
		else
		{
			$this->show_message($_LANG['edit_password_failure'], $_LANG['back_page_up'], '', 'info');
		}
	
	}
	//用户订单
	public function userorder(){
		$this->un_login();
        LC('@.Help.order');
		$_LANG=L();
		$user_id = $_SESSION['user_id'];
		$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;

		$record_count = G('db')->getOne("SELECT COUNT(*) FROM " .gettable('order_info'). " WHERE user_id = '$user_id'");

		$pager  = get_pager(U('userorder',array('act'=>1)),'', $record_count, $page,10);

		$orders = get_user_orders($user_id, $pager['size'], $pager['start']);
		$merge  = get_user_merge($user_id);
   
		$this->assign('merge',  $merge);
		$this->assign('lang',  $_LANG);
		$this->assign('pager',  $pager);
		$this->assign('orders', $orders);
		$this->display();
	}
	//用户红包
	public function userbonus(){
			$this->un_login();
			LC('@.Help.order');
			$_LANG=L();
			$user_id = $_SESSION['user_id'];
			//$page = $this->getby('page');
			//$page = $page? intval($page) : 1;
			$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;

			$record_count = G('db')->getOne("SELECT COUNT(*) FROM " .gettable('user_bonus'). " WHERE user_id = '$user_id'");

			$pager  = get_pager(U('userbonus',array('act'=>1)),'', $record_count, $page,10);
			$bonus=get_user_bonus($user_id,$pager['size'],$pager['start']);

			$this->assign('lang',  $_LANG);
			$this->assign('pager',  $pager);
			$this->assign('bonus', $bonus);
			$this->display();
	}
	public function addbonus(){
		$this->un_login();
		$_LANG=L();
		$user_id = $_SESSION['user_id'];
		$bouns_sn=isset($_POST['sn'])?trim($_POST['sn']):'';
		if(add_bonus($user_id, $bouns_sn)!==false){
			$this->show_message($_LANG['add_bonus_sucess'], $_LANG['back'], U('User/userbonus'), 'info');
		}else{
			$this->show_message($_LANG['add_bonus_false'], $_LANG['back'], U('User/userbonus'), 'error');
		}
	}
	//用户购物车
	public function shopbag(){
		$this->un_login();
		$this->display();
	}
	//用户收藏
	public function userfavorites(){
		$this->un_login();
		$this->display();
	}
	//保存修改资料
	public function usersave(){
		$this->un_login();
	    $_LANG=L();
		  $user_id = $_SESSION['user_id'];
		// $birthday = trim($_POST['birthdayYear']) .'-'. trim($_POST['birthdayMonth']) .'-'.
		//trim($_POST['birthdayDay']);
		$user_name = trim($_POST['user_name']);
		$email = trim($_POST['email']);
		$sex = trim($_POST['sex']);
		$age = trim($_POST['age']);
		$occupation = trim($_POST['occupation']);
	 	$msn = trim($_POST['msn']);
		$qq = trim($_POST['qq']);
		$mobile_phone = trim($_POST['mobile_phone']);
		$office_phone = $_POST['office_phone'];
		$home_phone = $_POST['home_phone'];
	 
        $uid=G('user')->check_user($user_name);
	 
		if (!empty($uid)&&($uid!=$user_id)){
			$this->show_message($_LANG['passport_js']['msg_un_registered']);
		}

		if (!empty($office_phone) && !preg_match( '/^[\d|\_|\-|\s]+$/', $office_phone ) )
		{
			$this->show_message($_LANG['passport_js']['office_phone_invalid']);
		}
		if (!empty($home_phone) && !preg_match( '/^[\d|\_|\-|\s]+$/', $home_phone) )
		{
			 $this->show_message($_LANG['passport_js']['home_phone_invalid']);
		}
		if (!is_email($email))
		{
			$this->show_message($_LANG['msg_email_format']);
		}
		if (!empty($msn) && !is_email($msn))
		{
			 $this->show_message($_LANG['passport_js']['msn_invalid']);
		}
		if (!empty($qq) && !preg_match('/^\d+$/', $qq))
		{
			 $this->show_message($_LANG['passport_js']['qq_invalid']);
		}
		if (!empty($mobile_phone) && !preg_match('/^\d+$/', $mobile_phone))
		{
			$this->show_message($_LANG['passport_js']['mobile_phone_invalid']);
		}


		$profile  = array(
			'user_name'  => $user_name,
			'user_id'  => $user_id,
			'email'    => $email,
			'sex'=>		$sex,
			'other'=> array(
				'age'=>		$age,
				'occupation'=>		$occupation,
				'msn'=>		$msn,
				'qq'=>		$qq,
				'mobile_phone'=>		$mobile_phone,
				'office_phone'=>		$office_phone,
				'home_phone'=>		$home_phone
			)
			);


		if (edit_profile($profile))
		{
			$this->show_message($_LANG['edit_profile_success'], $_LANG['profile_lnk'], U('User/useredit'), 'info');
		}
		else
		{
			if ($user->error == ERR_EMAIL_EXISTS)
			{
				$msg = sprintf($_LANG['email_exist'], $profile['email']);
			}
			else
			{
				$msg = $_LANG['edit_profile_failed'];
			}
			$this->show_message($msg, '', '', 'info');
		}
	}
	#收货人信息;
	function address(){
	
		//$this->un_login();
		$_LANG=L();
		$user_id = $_SESSION['user_id'];
		$this->assign('lang',  $_LANG);

		/* 取得国家列表、商店所在国家、商店所在国家的省列表 */
		$this->assign('country_list',       get_regions());
		$this->assign('shop_province_list', get_regions(1, $_CFG['shop_country']));

		/* 获得用户所有的收货人信息 */
		$consignee_list = get_consignee_list($_SESSION['user_id']);

		if (count($consignee_list) < 5 && $_SESSION['user_id'] > 0){

			/* 如果用户收货人信息的总数小于5 则增加一个新的收货人信息 */
			$consignee_list[] = array('country' => $_CFG['shop_country'], 'email' => isset($_SESSION['email']) ? $_SESSION['email'] : '');
		}

		$this->assign('consignee_list', $consignee_list);
//dump($consignee_list);
		//取得国家列表，如果有收货人列表，取得省市区列表
		foreach ($consignee_list AS $region_id => $consignee)
		{
			$consignee['country']  = isset($consignee['country'])  ? intval($consignee['country'])  : 0;
			$consignee['province'] = isset($consignee['province']) ? intval($consignee['province']) : 0;
			$consignee['city']     = isset($consignee['city'])     ? intval($consignee['city'])     : 0;

			$province_list[$region_id] = get_regions(1, $consignee['country']);
			$city_list[$region_id]     = get_regions(2, $consignee['province']);
			$district_list[$region_id] = get_regions(3, $consignee['city']);
		}

		/* 获取默认收货ID */
		$address_id  = G('db')->getOne("SELECT address_id FROM " .gettable('users'). " WHERE user_id='$user_id'");

		//赋值于模板
		$this->assign('real_goods_count', 1);
		$this->assign('shop_country',     $_CFG['shop_country']);
		$this->assign('shop_province',    get_regions(1, $_CFG['shop_country']));
		$this->assign('province_list',    $province_list);
		$this->assign('address',          $address_id);
		$this->assign('city_list',        $city_list);
		$this->assign('district_list',    $district_list);
		$this->assign('currency_format',  $_CFG['currency_format']);
		$this->assign('integral_scale',   $_CFG['integral_scale']);
		$this->assign('name_of_region',   array($_CFG['name_of_region_1'], $_CFG['name_of_region_2'], $_CFG['name_of_region_3'], $_CFG['name_of_region_4']));
	   
		
		$this->display();
	}
	//更新收货人地址
	public function act_edit_address(){
		$this->un_login();
		$_LANG=L();
		$this->assign('lang', $_LANG);
		$user_id = $_SESSION['user_id'];
		$address = array(
			'user_id'    => $user_id,
			'address_id' => intval($_POST['address_id']),
			'country'    => isset($_POST['country'])   ? intval($_POST['country'])  : 0,
			'province'   => isset($_POST['province'])  ? intval($_POST['province']) : 0,
			'city'       => isset($_POST['city'])      ? intval($_POST['city'])     : 0,
			'district'   => isset($_POST['district'])  ? intval($_POST['district']) : 0,
			'address'    => isset($_POST['address'])   ? trim($_POST['address'])    : '',
			'consignee'  => isset($_POST['consignee']) ? trim($_POST['consignee'])  : '',
			'email'      => isset($_POST['email'])     ? trim($_POST['email'])      : '',
			'tel'        => isset($_POST['tel'])       ? make_semiangle(trim($_POST['tel'])) : '',
			'mobile'     => isset($_POST['mobile'])    ? make_semiangle(trim($_POST['mobile'])) : '',
			'best_time'  => isset($_POST['best_time']) ? trim($_POST['best_time'])  : '',
			'sign_building' => isset($_POST['sign_building']) ? trim($_POST['sign_building']) : '',
			'zipcode'       => isset($_POST['zipcode'])       ? make_semiangle(trim($_POST['zipcode'])) : '',
			);

		if (update_address($address))    {
			$this->show_message($_LANG['edit_address_success'], $_LANG['address_list_lnk'], U('address'));
		}
	
	}
	public function drop_consignee(){
	$this->un_login();
	    $_LANG=L();
		$consignee_id = intval($this->getby('id'));

		if (drop_consignee($consignee_id))
		{
			mdl_header("Location: ".U('address')."\n");
			exit;
		}
		else
		{
			$this->show_message($_LANG['del_address_false']);
		}
	
	}
    //取消订单
	public function cancel_order(){
		$this->un_login();
		$this->un_login();
        LC('@.Help.order');
		$_LANG=L();
		$user_id = $_SESSION['user_id'];
		$order_id=$this->getby('order_id');
		$order_id = isset($order_id) ? intval($order_id) : 0;
		if (cancel_order($order_id, $user_id))
		{
			mdl_header("Location: ".U('userorder')."\n");
			exit;
		}else{
			G('err')->show($_LANG['order_list_lnk'], U('userorder'));
		}
		
	}
	//订单详情
	public function detail(){
		$this->un_login();
		  LC('@.Help.order');
		$_LANG=L();
		$user_id = $_SESSION['user_id'];
	    $order_id=$this->getby('orderid');
		$order_id = isset($order_id) ? intval($order_id) : 0;

		/* 订单详情 */
		$order = get_order_detail($order_id, $user_id);

		if ($order === false){
			G('err')->show($_LANG['back_home_lnk'], './');

			exit;
		}	

		/* 订单商品 */
		$goods_list = order_goods($order_id);
		foreach ($goods_list AS $key => $value)
		{
			$goods_list[$key]['market_price'] = price_format($value['market_price'], false);
			$goods_list[$key]['goods_price']  = price_format($value['goods_price'], false);
			$goods_list[$key]['subtotal']     = price_format($value['subtotal'], false);
		}

		 /* 设置能否修改使用余额数 */
		if ($order['order_amount'] > 0)
		{
			if ($order['order_status'] == OS_UNCONFIRMED || $order['order_status'] == OS_CONFIRMED)
			{
				$user = user_info($order['user_id']);
				if ($user['user_money'] + $user['credit_line'] > 0)
				{
					$this->assign('allow_edit_surplus', 1);
					$this->assign('max_surplus', sprintf($_LANG['max_surplus'], $user['user_money']));
				}
			}
		}

		/* 未发货，未付款时允许更换支付方式 */
		if ($order['order_amount'] > 0 && $order['pay_status'] == PS_UNPAYED && $order['shipping_status'] == SS_UNSHIPPED)
		{
			$payment_list = available_payment_list(false, 0, true);

			/* 过滤掉当前支付方式和余额支付方式 */
			foreach ($payment_list as $key => $payment)
			{
				if ($payment['pay_id'] == $order['pay_id'] || $payment['pay_code'] == 'balance')
				{
					unset($payment_list[$key]);
				}
			}
			$this->assign('payment_list', $payment_list);
		}

		/* 订单 支付 配送 状态语言项 */
		$order['order_status'] = $_LANG['os'][$order['order_status']];
		$order['pay_status'] = $_LANG['ps'][$order['pay_status']];
		$order['shipping_status'] = $_LANG['ss'][$order['shipping_status']];
		//dump($order);
 		$this->assign('order',      $order);
		$this->assign('lang',      $_LANG);
	 
		$this->assign('goods_list', $goods_list);
	    $this->display();
	
	}
	public function save_order_address(){
		$this->un_login();
		  $_LANG=L();
		  $address = array(
			'consignee' => isset($_POST['consignee']) ? trim($_POST['consignee'])  : '',
			'email'     => isset($_POST['email'])     ? trim($_POST['email'])      : '',
			'address'   => isset($_POST['address'])   ? trim($_POST['address'])    : '',
			'zipcode'   => isset($_POST['zipcode'])   ? make_semiangle(trim($_POST['zipcode'])) : '',
			'tel'       => isset($_POST['tel'])       ? trim($_POST['tel'])        : '',
			'mobile'    => isset($_POST['mobile'])    ? trim($_POST['mobile'])     : '',
			'sign_building' => isset($_POST['sign_building']) ? trim($_POST['sign_building']) : '',
			'best_time' => isset($_POST['best_time']) ? trim($_POST['best_time'])  : '',
			'order_id'  => isset($_POST['order_id'])  ? intval($_POST['order_id']) : 0
			);
		if (save_order_address($address, $user_id))
		{
			mdl_header('Location: '.U('order_detail',array('order_id'=>$address['order_id'])).'');
			exit;
		}
		else
		{
			G('err')->show($_LANG['order_list_lnk'], U('order_list'));
		}
	
	}
	
	 	//验证码图片
	public function code_img(){
		LC("M.lib.seccode",true);
		$seccode = rand(100000, 999999);
		if(isset($_SESSION['scode'])){
			unset($_SESSION['scode']);
		}
		$_SESSION['scode']=$seccode;
		$code = new seccode();
		$code->code = $seccode;
		$code->type = 1;
		$code->width = 70;
		$code->height = 21;
		$code->background = 1;
		$code->adulterate = 0;
		$code->ttf = 1;
		$code->angle = 0;
		$code->color = 0;
		$code->size = 0;
		$code->shadow = 0;
		$code->animator = 0;
		$code->display();
	}
	//用户注册 用户名是否存在
	public function checkuid(){
		$userid= isset($_POST['userid'])?intval(trim($_POST['userid'])):'';
		$username = isset($_POST['username']) ?trim($_POST['username']):'';
		if($userid){
			$sql="select email,user_name from ".gettable('users')." where user_id =".$userid;
			$res=G('db')->getRow($sql);
			$email=$res['email'];
		}
		if(isset($email)&&$email==$username){
			echo 0;
		}else{
			if($username&&!preg_match("/[^0-9a-z@_.-]/i",$username)){
				$sql="select * from ".gettable('users')." where email='".$username."'";
				$res = G('db')->query($sql);
				if(G('db')->fetchRow($res)){
					echo 1;
				}else{
					echo 0;
				}
			}else{
				echo 0;
			}
		}
	}
	//用户名修改 用户名是否存在
	public function checkuname(){
		$userid= isset($_POST['userid'])?intval(trim($_POST['userid'])):'';
		$username = isset($_POST['username']) ?trim($_POST['username']):'';
		if($userid){
			$sql="select email,user_name from ".gettable('users')." where user_id =".$userid;
			$res=G('db')->getRow($sql);
			$user_name=$res['user_name'];
		}
		if(isset($user_name)&&$user_name==$username){
			echo 0;
		}else{
			if($username){
				$sql="select * from ".gettable('users')." where user_name='".$username."'";
				$res = G('db')->query($sql);
				if(G('db')->fetchRow($res)){
					echo 1;
				}else{
					echo 0;
				}
			}else{
				echo 0;
			}
		}
	}
}
?>